/*
2022-3-6
https://www.acwing.com/problem/content/4313/
*/
#include<cstring>
#include<iostream>
#include<algorithm>
#include<vector>

using namespace std;
const int N=2e5+10;
int n,m;
vector<int> g[N];
int q[N],p[N],top;
int sz[N];

void dfs(int u)
{
    sz[u]=1;
    q[top]=u,p[u]=top;
    top++;
    for(auto v:g[u])
    {
        dfs(v);
        sz[u]+=sz[v];
    }
}

int main()
{
    cin>>n>>m;
    for(int i=2;i<=n;i++)
    {
        int t;
        cin>>t;
        g[t].push_back(i);
    }
    
    dfs(1);
    
    while(m--)
    {
        int u,k;
        cin>>u>>k;
        if(k>sz[u]) cout<<"-1"<<endl;
        else cout<<q[p[u]+k-1]<<endl;
    }
    
    return 0;
}

